package com.example.constellation.luckfrag;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.constellation.R;
import java.util.List;
public class LuckAnalysisAdapter extends BaseAdapter{
        Context context;
        List<Luck_itemBean> mDatas;

    public LuckAnalysisAdapter(Context context, List<Luck_itemBean> mDatas) {
        this.context = context;
        this.mDatas = mDatas;
    }

    @Override
        public int getCount() {
            return mDatas.size();
        }

        @Override
        public Object getItem(int i) {
            return mDatas.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
           ViewHolder holder=null;
            if(view==null){
                view= LayoutInflater.from(context).inflate(R.layout.item_luckanalysis_iv,null);
                holder =new ViewHolder(view);
                view.setTag(holder);
            }else {
                holder=(ViewHolder) view.getTag();
            }
            Luck_itemBean bean=mDatas.get(i);
            holder.titleTv.setText(bean.getTitle());
            holder.contentTv.setText(bean.getContent());
            //改变textview的背景颜色
            GradientDrawable drawable= (GradientDrawable) holder.titleTv.getBackground();
            System.out.println("colorid="+bean.getColorId());
            drawable.setColor(bean.getColorId());
            return view;
        }

        class ViewHolder{
            TextView titleTv,contentTv;
            public ViewHolder(View view){
                titleTv=view.findViewById(R.id.item_luckanalysis_tv_title);
                contentTv=view.findViewById(R.id.item_luckanalysis_tv_content);
            }
        }

}
